package cn.zf233.xcloud.config.lockpool;

import cn.zf233.xcloud.config.RedissonConfig;
import cn.zf233.xcloud.config.lockpool.impl.ClusterXCloudThreadPool;
import cn.zf233.xcloud.config.lockpool.impl.SingleXCloudThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zf233 on 2021/6/1
 * 线程池配置类
 */
@Configuration
public class LockPoolConfig {

    private final Logger logger = LoggerFactory.getLogger(LockPoolConfig.class);

    @Bean(name = "lockPool")
    @ConditionalOnMissingBean(RedissonConfig.class)
    public SingleXCloudThreadPool singleXCloudThreadPool() {
        this.logger.info(" **** XCloud STARTER AND SINGLE THREAD_POOL INIT --------> ");
        return new SingleXCloudThreadPool();
    }

    @Bean(name = "lockPool")
    @ConditionalOnBean(RedissonConfig.class)
    public ClusterXCloudThreadPool clusterCloudThreadPool() {
        this.logger.info(" **** XCloud STARTER AND CLUSTER THREAD_POOL INIT -------> ");
        return new ClusterXCloudThreadPool();
    }
}
